
<template>
  <div>
    <TsDialog
      type="modal"
      :isShow.sync="showDialog"
      :title="$t('term.autoexec.savejob')"
    >
      <TsForm
        ref="formConfig"
        v-model="formValueConfig"
        v-bind="formConfig"
        type="type"
      ></TsForm>
      <template v-slot:footer>
        <Button @click="close()">{{ $t('page.cancel') }}</Button>
        <Button :loading="isCreating" type="primary" @click="onOk()">{{ $t('page.confirm') }}</Button>
      </template>
    </TsDialog>
  </div>
</template>
<script>
export default {
  name: '',
  components: {
    TsForm: () => import('@/resources/plugins/TsForm/TsForm')
  },
  filters: {
  },
  model: {
    prop: 'visible',
    event: 'change'
  },
  props: {
    isCreating: {type: Boolean}
  },
  data() {
    let _this = this;
    return {
      showDialog: true,
      formConfig: {
        itemList: {
          planStartTime: {
            type: 'datetime',
            transfer: true,
            label: this.$t('page.plantime'),
            desc: this.$t('term.autoexec.taskexpirationtip'),
            selectableRange: () => {
              const now = new Date().getTime();
              return [now + 5 * 60 * 1000, 0];
            },
            validateList: ['required']
          },
          triggerType: {
            type: 'select',
            transfer: true,
            label: this.$t('term.autoexec.triggertype'),
            dataList: [],
            validateList: ['required']
          }
        }
      },
      formValueConfig: {
        planStartTime: null,
        triggerType: null
      }
    };
  },
  beforeCreate() {},
  created() {
    this.initData();
  },
  beforeMount() {},
  mounted() {},
  beforeUpdate() {},
  updated() {},
  activated() {},
  deactivated() {},
  beforeDestroy() {},
  destroyed() {},
  methods: {
    initData() {
      this.getTriggerTypeLit();
      this.formValueConfig.planStartTime = (new Date()).getTime() + 60 * 10 * 1000; //默认十分钟之后
    },
    getTriggerTypeLit() { //触发方式
      let data = {enumClass: 'neatlogic.framework.autoexec.constvalue.JobTriggerType'};
      this.$api.common.getSelectList(data).then(res => {
        if (res.Status == 'OK') {
          let dataList = res.Return || [];
          this.formConfig.itemList.triggerType.dataList = dataList;
          dataList.length > 1 && (this.formValueConfig.triggerType = dataList[1].value);
        }
      });
    },
    getDataList() {
      let num = 10;
      let dataList = [];
      for (let i = 0; i <= num; i++) {
        dataList.push({value: Math.pow(2, i)});
      }
      return dataList;
    },
    onOk() {
      if (this.$refs.formConfig.valid()) {
        this.$emit('on-ok', this.$refs.formConfig.getFormValue());
      }
    },
    close() {
      showDialog = false;
    }
  },
  computed: {

  },
  watch: {
    showDialog() {
      this.$emit('change', this.showDialog);
    }
  }
};
</script>
